package com.ruoyi.tmsdriveracc.utils;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @ClassName: MessageReceive
 * @Description: 消息监听
 * @Author 小何
 * @Date 2022/4/20 21:27
 * @version: 1.0
 */
@Component
public class MessageReceiveOne {

    @Autowired
    private SmsUtil smsUtil;
    //监听queueSmsOne队列
    @RabbitListener(queuesToDeclare = @Queue("queueSms"))
    public void receiveMessage(Message message) throws UnsupportedEncodingException {

        String msg = new String(message.getBody(), "utf-8");
        Map<String,String> map = JSON.parseObject(msg, Map.class);
        String phone = map.get("Mobile");
        try {
            smsUtil.sendSmsTest(phone, null);
            System.out.println("11");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

